//Write by oshogbo//vx
//23.07.2011
//http://code.google.com/p/streamobs

class LiveStream extends Stats implements ChannelType
{
  private String name;
  private boolean live = false;
  private static final String addres = "http://www.livestream.com/";
  private static final String hostName = "channel.api.livestream.com";
  private static final String headerStart = "GET /1.0/info?channel=";
  private static final String headerEnd = " HTTP/1.1\r\nHost: channel.api.livestream.com\r\nUser-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; pl; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
  private String header;

  public LiveStream(String name)
  {
    this.name = name;
    header = headerStart + name + headerEnd;
  }

  public String getName()
  {
    return name;
  }

  public String getAddres()
  {
    return addres + name; 
  }

  public boolean isLive()
  {
    return live;
  }

  public void checkStatus()
  {
    String answer = refresh(hostName, header);
    int pos;
    
    if(answer != null && (pos = answer.indexOf("<ls:isLive>")) != -1 )
    {
      String answer2 = answer.substring(pos + 11, pos + 15);

      if(answer2.equals("true"))
	live = true;
      else
	live = false;
    }else 
      live = false;
  }

}
